package zhujie.service.impl;

import zhujie.dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zhujie.entity.Student;
import zhujie.service.ModifyService;

//@Service       =  <bean id="modifyServiceImpl" class="zhujie.txt.service.impl.ModifyServiceImpl">
@Service("modifyService") // =  <bean id="modifyService" class="zhujie.txt.service.impl.ModifyServiceImpl">
@Transactional
public class ModifyServiceImpl implements ModifyService {

//    @Autowired //autowired by type    (use on setter is recommended)
//    @Qualifier("studentDao") //check bean name
    private StudentDao studentDao;

//    @Value("10") //set value to normal field
//    private int anInt;

    public StudentDao getStudentDao() {
        return studentDao;
    }

    @Autowired
    public void setStudentDao(@Qualifier("studentDao")StudentDao studentDao) {
        this.studentDao = studentDao;
    }

    @Override
    public Integer insertStudent(Student student) {
        return studentDao.insertStudent(student);
    }

    @Override
    public Integer deleteStudent(int studentId) {
        return studentDao.deleteStudent(studentId);
    }

    @Override
    public Integer updateStudent(Student student) {
        //test roll back function by txmanager
//        if(1==1) {
//            throw new RuntimeException("RuntimeException");
//        }
        return studentDao.updateStudent(student);
    }
}
